﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class restaurant_RegisterProvider : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitData();
            InitForm();
        }
    }

    protected void InitData()
    {
    }
    protected void InitForm()
    {
        username_textbox.Focus();
    }
    protected void UpdateNotice(String notice,bool isWarning)
    {
        notice_lable.Text = notice;

        if (isWarning)
            notice_lable.ForeColor = System.Drawing.Color.Red;
    }

    protected void OnRadioBtnAgreeChecked(object sender, EventArgs e)
    {
        submit_button.Enabled = true;
    }
    protected void OnSubmitBtnClick(object sender, EventArgs e)
    {
        String pwd = pwd_textbox.Text.Trim();
        String repwd = repwd_textbox.Text.Trim();

        if (!pwd.Equals(repwd))
        {
            UpdateNotice("两次密码输入不一致,请重新输入!", true);
            return;
        }

        Entities.Owner owner = new Entities.Owner();
        owner.Name = username_textbox.Text.Trim();
        owner.Phone = mobile_textbox.Text.Trim();
        owner.IdCard = idcard_textbox.Text.Trim();
        owner.Pwd = pwd;

        if (!BLL.Command.RegisterProvider(ref owner))
        {
            UpdateNotice("失败,请检查用户名，电话或者身份证号码是否已经注册过!", true);
        }
        else
        {
            //Session["owner_name"] = username;
            Session["owner_id"] = owner.Id;
            //UpdateNotice("注册成功，下一步可以添加您的餐厅信息!", false);
            Response.Redirect("~/restaurant/admin.aspx?owner_id=" + owner.Id);
        }

    }
}
